package org.example.maven.service.Impl;

import com.github.pagehelper.PageHelper;
import org.example.maven.mapper.PositionMapper;
import org.example.maven.pojo.position.AddPosition;
import org.example.maven.pojo.position.PositionListTable;
import org.example.maven.pojo.position.SearchPosition;
import org.example.maven.pojo.position.utils.PositionSelect;
import org.example.maven.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PositionServiceImpl implements PositionService {
    @Autowired
    private PositionMapper positionMapper;

    @Override
    public List<PositionListTable> getAllPositionList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return positionMapper.getAllPositionList();
    }

    @Override
    public void addPosition(AddPosition addPosition) {
        positionMapper.addPosition(addPosition);
    }

    @Override
    public Integer getPositionCount(SearchPosition searchPosition) {
        return positionMapper.getPositionCount(searchPosition);
    }

    @Override
    public List<PositionListTable> getSpeciePosition(SearchPosition searchPosition,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return positionMapper.getSpeciePosition(searchPosition);
    }

    @Override
    public void deletePosition(String []id) {
        positionMapper.deletePosition(id);
    }

    @Override
    public AddPosition getEditPosition(Integer id) {
        return positionMapper.getEditPositionDetail(id);
    }

    @Override
    public void updatePosition(AddPosition addPosition) {
        positionMapper.updatePosition(addPosition);
    }

    @Override
    public AddPosition getPositionLive(String name) {
        return positionMapper.getPositionLive(name);
    }

    @Override
    public AddPosition getPositionIsDeletedLive(String name) {
        return positionMapper.getPositionIsDeletedLive(name);
    }

    @Override
    public void updatePositionIsDeleted(AddPosition addPosition) {
        positionMapper.updatePositionIsDeleted(addPosition);
    }

    @Override
    public List<Map<String, String>> getPositionByDepartmentId(Integer id) {
        List<PositionSelect> list= positionMapper.getPositionByDepartmentId(id);
        List<Map<String,String>> result=new ArrayList<>();
        for(PositionSelect p:list){
            Map<String,String> map=new HashMap<>();
            map.put("label",p.getLabel());
            map.put("value",p.getValue());
            result.add(map);
        }
        return result;
    }
}
